package com.my.biao.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * 项目名称：BiAo
 * 创建人：偏好设置
 * 创建时间：2018/7/26 16:37
 */

public class SharedPrefUtil {

    private SharedPreferences.Editor mEditor;
    private SharedPreferences mSharedPreferences;

    public SharedPrefUtil(Context context, String name) {
        mSharedPreferences = context.getSharedPreferences(name, Context.MODE_PRIVATE);
        mEditor = mSharedPreferences.edit();
    }

    public void putString(String key, String value) {
        mEditor.putString(key, value);
    }

    public void putInt(String key, int value) {
        mEditor.putInt(key, value);
    }

//	public void putDouble(String key, double d) {
//		mEditor.putFloat(key, (float) d);
//	}

    public void putLong(String key, long value) {
        mEditor.putLong(key, value);
    }

    public void putBoolean(String key, boolean value) {
        mEditor.putBoolean(key, value);
    }

    public int getInt(String key, int defaultValue) {
        return mSharedPreferences.getInt(key, defaultValue);
    }

    public boolean getBoolean(String key, boolean defaultValue) {
        return mSharedPreferences.getBoolean(key, defaultValue);
    }

//	public double getDouble(String key, double defaultValue) {
//		// return mSharedPreferences.getFloat(key, (float) defaultValue);
//		return Double.parseDouble(String.valueOf(mSharedPreferences.getFloat(key, (float) defaultValue)));
//	}

    public long getLong(String key, long defaultValue) {
        return mSharedPreferences.getLong(key, defaultValue);
    }

    public String getString(String key, String defaultValue) {
        return mSharedPreferences.getString(key, defaultValue);
    }

    public void commit() {
        mEditor.commit();
    }

    public void delete(String key) {
        mEditor.remove(key);
    }

    public void clear() {
        mEditor.clear();
        mEditor.commit();
    }
}
